package tickets;

/**
 * Created by dllo on 18/4/17.
 */
public class TicketOffice {
    private int tickets = 100;
    private final Object lock = new Object();


    public boolean sellTicker() {
        synchronized (lock) {
            if (tickets <= 0) {
                return false;
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            tickets--;
            System.out.println(Thread.currentThread().getName() + "卖出一张票,还剩:" + tickets + "张");
            return true;
        }
    }
}
